<%@page import="java.util.List"%>
<%@page import="models.DealModel"%>
<%@page import="models.GeoModel"%>
<%@page import="java.util.ArrayList"%>
<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="java.util.TreeMap"%>
<%@page import="helpers.UrlHelper"%>

<%
TreeMap check = (TreeMap) request.getAttribute("check");
String success = (String) request.getAttribute("success");
String form = (String) request.getAttribute("form");
ArrayList<GeoModel> cities = (ArrayList<GeoModel>) request.getAttribute("cities");
String city = (String) request.getAttribute("city");
List<DealModel> deals = (List<DealModel>) request.getAttribute("deals");
%>

<jsp:include page="/admin/layouts/header.jsp">
    <jsp:param name="language" value="1" />
</jsp:include>

<script type="text/javascript" src="/admin/js/list_form.js"></script>
<script type="text/javascript" src="/admin/js/add_deal_email.js"></script>
		
		<div class="maincontent noright">
        	<div class="maincontentinner">
                <ul class="maintabmenu multipletabmenu">
                	<li><a href="/admin/dealsemail/list">Danh sách Deal Email</a></li>
                	<li class="current"><a href="/admin/dealsemail/create">Tạo Deal Email</a></li>
                </ul><!--maintabmenu-->
                
                <div class="content">
					<% if (success != null) {%>
					<div class="notification msgsuccess">
                        <a class="close"></a>
                        <p><%=success %></p>
                    </div>
					<% } %>
                    <div class="contenttitle">
                    	<h2 class="form"><span>Tạo email deal marketing</span></h2>
                    </div><!--contenttitle-->
                    
                    <br>
            
                    <form class="stdform" id="deal_email_form" action="" method="get">
                    	
                        <p>
                        	<label>Chọn Tỉnh/Thành phố</label>
                            <span class="field">
                            	<select name="city">
                            		<% for (int i = 0; i < cities.size(); i++) { %>
                            		<option value="<%=cities.get(i).getGeoId()%>" <%=(city != null && city.equalsIgnoreCase(cities.get(i).getGeoId())) ? "selected=\"selected\"" : "" %>><%=cities.get(i).getName() %></option>
                            		<% } %>
                            	</select>
                            </span>
                        </p>
                        <p class="stdformbutton">
                        	<button class="submit radius2">Lấy danh sách deal</button>
                        </p>
                        
                    </form>
                    
                    <br clear="all">
                    <br clear="all">
                    
                    <% if (deals.size() > 0) { %>
                    <jsp:include page="/admin/elements/message.jsp" />
                    
                    <form class="stdform stdform2" id="deal_list_form" action="" method="post">
	                    <div class="contenttitle radiusbottom0">
		                	<h2 class="table"><span>Chọn danh sách deal</span></h2>
		                </div>
		                
		                <p>
                        	<label>Nhập tiêu đề cho email</label>
                            <span class="field">
                            	<input type="text" class="smallinput" name="title" id="d_title" value="">
                            	<% if (check.get("title") != null) { %>
									<label for="d_title" generated="true" class="error"><%=check.get("title") %></label>
								<% } %>
                            </span>
                        </p>
                        <p>
                        	<label>Chọn Mail Server</label>
                            <span class="field">
                            	<select name="mailServer">
                            		<option value="amazon">Server Mail Amazon</option>
                            		<option value="google">Server Mail Google App Engine</option>
                            	</select>
                            	<% if (check.get("mailServer") != null) { %>
									<label for="d_mailServer" generated="true" class="error"><%=check.get("mailServer") %></label>
								<% } %>
                            </span>
                        </p>
		                
	                    <table cellspacing="0" cellpadding="0" border="0" class="stdtable stdtablecb" id="list-table">
		                    <colgroup>
		                        <col class="con0">
		                        <col class="con1">
		                        <col class="con0">
		                        <col class="con1">
		                        <col class="con0">
		                    </colgroup>
		                    <thead>
		                        <tr>
		                        	<th class="head0"><span class="checkbox"><input type="checkbox" class="checkall"></span></th>
		                            <th class="head1">Mã Deal</th>
		                            <th class="head0">Tên Deal</th>
		                            <th class="head1">Mã hợp đồng</th>
		                            <th class="head0">Tên sale</th>
		                            <th class="head1">Trạng thái</th>
		                        </tr>
		                    </thead>	                   
		                    <tbody>
		                    	<% for (int i = 0; i < deals.size(); i++) { %>
		                        <tr>
		                        	<td class="center"><span class="checkbox"><input type="checkbox" value="<%=deals.get(i).getDealId()%>"></span></td>
									<td class="center"><%=deals.get(i).getDealId() %></td>
		                            <td><%=deals.get(i).getAbbreviation() %></td>
		                            <td><%=deals.get(i).getContractCode() %></td>
		                            <td><%=deals.get(i).getUsername() %></td>
		                            <td class="center">
		                            	<%
										switch (deals.get(i).getStatus()) {
											case 0: 
												%>Chưa kích hoạt<%
												break;
											case 1:
												%>Đang kích hoạt<%
												break;
											case 2:
												%>Đang chạy<%
												break;
											case 3:
												%>Kết thúc<%
												break;
											case 4:
												%>Đã khóa<%
												break;
											case 5:
												%>Hoàn thành<%
												break;
											default:
												%>Chưa kích hoạt<%
												break;											
										}
										%>
		                            </td>
		                        </tr>
		                        <% } %>
		                    </tbody>
		                </table>
	                	<br class="clearall"/>
	                	<input type="hidden" name="ids" value="">
	                    <p>
	                    	<button class="stdbtn btn_blue">Tạo email</button>
	                    </p>
                    <% } %>
                    </form>
                </div><!--content-->
                
            </div><!--maincontentinner-->
            
            <jsp:include page="/admin/elements/copyright.jsp">
            	<jsp:param name="language" value="1" />
			</jsp:include>
            
        </div>

<jsp:include page="/admin/layouts/footer.jsp">
    <jsp:param name="language" value="1" />
</jsp:include>